﻿#pragma once
#include <string>
#include <map>
//#include "OrderData.h"
#include "CTPTradeLib.h"
#include "FrameData.h"
#include "Trader.h"
//#define Trade_RealDisk // 实盘的定义

// 所有的下单操盘
class MarketService : public Trader
{
public:
	MarketService();
	~MarketService();

	// 处理行情数据
	void DealFrameDataList(const std::list<FData::FrameKItem> &pframeList);
	// 返回CTP是否连接正常
	bool IsCTPConnected();
	// CTP下单函数
	virtual void InsertCTPOrder(const TD::OrderOption &pOption, TD::OrderBackFunc pFunc) override;
protected:
	//// 初始化做单信息之前的回调
	//virtual void onBeforeInitOrderInfo();
	//// 检查量化周期里没有订单信息的回调
	//virtual void toCheckRealNoOrder(const std::string &pSymbolName, WaveFormData::WaveBreakPoint &ioCircle);
	//// 平仓回调
	//virtual void onCloseOrder(const std::string &pSymbol, OrderData::QuantityOrderInfo &pOrder, MData::PriceItem &pItem);
	//// 开仓回调
	//virtual void onOpenOrder(const std::string &pSymbol, OrderData::QuantityOrderInfo &pOrder, MData::PriceItem &pItem);
	//virtual void onFrameTradeOrder(const std::string &pSymbol, MData::PriceItem &priceItem, OrderSupport::PrepareData *supportData, FrameTradeOrder *pTradeOrder) override;
private:
	void init();
	//// 交易返回回调
	//void tradeFeedback(const std::string &pSymbol, float orderPrice, char pTimeStr[9]);
	//// 平仓
	//void closeOrder(const std::string &pSymbol, const OrderSupport::PrepareData &supportData, const Trader::FrameTradeOrder &pTradeOrder, MData::PriceItem &pItem);
	//// 开仓
	//void openOrder(const std::string &pSymbol, const OrderSupport::PrepareData &supportData, const Trader::FrameTradeOrder &pTradeOrder, MData::PriceItem &pItem);

	CTPTradeLib m_ctpModel;
	time_t m_lastInsertOrderTime; // 最近的下单时间

	//std::string m_workspace;
	time_t m_ctpDisconnectTime; // 记录ctp断开得时间
};

